home *** CD-ROM | disk | FTP | other *** search
- #include <Memory.h>
- #include <Devices.h>
- #include <LowMem.h>
- #include "IsDriverOpen.h"
-
- // Return driver ref if driver is open
-
- short IsDriverOpen(StringPtr driverName)
- {
- short dref;
- DCtlHandle dceHndl;
-
- dref = 0;
-
- dceHndl = FindTheDriver(driverName);
- if (dceHndl != NULL) {
-
- if ((*dceHndl)->dCtlFlags & dOpenedMask) // if open (bit 5)
- dref = (*dceHndl)->dCtlRefNum;
- }
-
- return dref;
- }
-
-
- // FindTheDriver
- // Return driver dctlhandle if it exists.
-
- DCtlHandle FindTheDriver(StringPtr driverName)
- {
- DCtlHandle EntryHand;
- short count;
- DCtlHandle *utable;
-
- EntryHand = NULL;
-
- // number of entries in unit table. LMGetUnitTableEntryCount isn't defined
- // for PowerPC, but this does the equivalent.
- count = GetPtrSize(LMGetUTableBase()) / sizeof(DCtlHandle);
- utable = (DCtlEntry ***) LMGetUTableBase();
-
- while (--count >= 0) {
- DCtlHandle entry;
-
- entry = *utable++;
- if (entry != NULL) {
- StringPtr namePtr;
-
- // see if ram based (test bit 6)
-
- if ((*entry)->dCtlFlags & dRAMBasedMask) {
-
- // in ram, so we have a handle
- namePtr = (StringPtr) (*(Handle)((*entry)->dCtlDriver)) + 18;
-
- } else {
-
- // in rom, so we have a pointer
- namePtr = (StringPtr) ((*entry)->dCtlDriver) + 18;
- }
-
- if (RelString(driverName, namePtr, FALSE, TRUE) == 0) {
-
- EntryHand = entry;
- break;
- }
- }
- }
-
- return (EntryHand);
- }
-